package models

import (
	"time"

	"gorm.io/gorm"
)

// MaActivityData [...]
type MaActivityData struct {
	ID              string    `gorm:"autoIncrement:true;primaryKey;column:id;type:int;not null" json:"id" json_old:"ID"`
	ActivityID      string    `gorm:"index:idx_actid;column:activity_id;type:int;not null;comment:引用的模板ID;" json:"activity_id" json_old:"ActivityID"`
	Title           string    `gorm:"column:title;type:varchar(30);not null;comment:客户活动标题" json:"title" json_old:"Title"`
	Content         string    `gorm:"column:content;type:text;not null;comment:客户资料内容" json:"content" json_old:"Content"`
	Phone           string    `gorm:"column:phone;type:varchar(20);not null;comment:手机号" json:"phone" json_old:"Phone"`
	AddTime         time.Time `gorm:"column:add_time;type:datetime;not null;comment:添加时间" json:"-" json_old:"-"`
	AddTimeFormated string    `gorm:"-" json:"add_time" json_old:"AddTime"`
	RedemptionCode  string    `gorm:"index:idx_redep;column:redemption_code;type:varchar(20);not null;comment:兑换码;" json:"redemption_code" json_old:"RedemptionCode"`
	CreatedAt       int64     `gorm:"index:created_at;column:created_at;autoCreateTime;type:int;size:64;comment:创建时间" json:"created_at"`
}

func (m *MaActivityData) AfterFind(tx *gorm.DB) (err error) {
	if !m.AddTime.IsZero() {
		addTimeByte, _ := DateTime(m.AddTime).MarshalDateTime()
		m.AddTimeFormated = string(addTimeByte)
	}
	return
}

// TableName get sql table name.获取数据库表名
func (m MaActivityData) TableName() string {
	return "ma_activity_data"
}

// 模式自动注册
func init() {
	Models = append(Models, &MaActivityData{})
}
